-- ArenaBox
-- Created by chengb Dec/16/2015
-- 角斗台储物箱格子

-- 初始化
function initArenaBox(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 音效
            AudioM.playFx("equip_unload");

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 如果可以领取奖励
            if ArenaM.canTakeBonus() then
                local function takeBonus()
                    local pos = self.gridData:getPos();
                    DungeonActionM.go("do_building_bonus", pos);
                end
                self:openBuildingView(takeBonus);
            else
                self:openBuildingView(nil, nil, buildingInfo["dialog2"], getLocStr("btn_text_leave"));
            end
        end
    end

    local iconIndex = buildingInfo["icon"];
    local iconPath = getLevelItemIconPath(iconIndex);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
